package com.xiaogao.serviceEdu.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiaogao.commonUtils.Result;
import com.xiaogao.serviceEdu.entity.EduCourse;
import com.xiaogao.serviceEdu.entity.EduTeacher;
import com.xiaogao.serviceEdu.service.EduCourseService;
import com.xiaogao.serviceEdu.service.EduTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 小高
 * @createtime 2021-06-24-16:44
 * @description 前台讲师控制器
 */
@RestController
@RequestMapping("/serviceEdu/index")
@Api(description = "前台首页管理")
public class IndexFrontController {

    @Autowired
    private EduCourseService courseService;
    @Autowired
    private EduTeacherService teacherService;

    @ApiOperation(value = "查询前8条热门课程，前4名讲师")
    @GetMapping("/getList")
    public Result getList(){
        // 查询前8条热门课程
        QueryWrapper<EduCourse> courseWrapper = new QueryWrapper<>();
        courseWrapper.orderByDesc("id");
        courseWrapper.last("limit 8");
        List<EduCourse> courseList = courseService.list(courseWrapper);

        // 查询前4名讲师
        QueryWrapper<EduTeacher> teacherWrapper = new QueryWrapper<>();
        teacherWrapper.orderByDesc("id");
        teacherWrapper.last("limit 4");
        List<EduTeacher> teacherList = teacherService.list(teacherWrapper);

        return Result.ok().data("courseList",courseList).data("teacherList",teacherList);
    }
}
